package com.dwy2002.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwy2002.common.Result;
import com.dwy2002.common.annotation.RequiresPermission;
import com.dwy2002.enums.Logical;
import com.dwy2002.pojo.dto.users.RegisterDTO;
import com.dwy2002.pojo.dto.users.UsersPageDTO;
import com.dwy2002.pojo.po.users.Users;
import com.dwy2002.pojo.vo.users.UserinfoVO;
import com.dwy2002.user.service.IUserManagerService;
import com.dwy2002.user.service.IUsersService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/16
 */
@RestController
@RequestMapping("/manager/users")
@RequiredArgsConstructor
public class UserManagerController {
    private final IUserManagerService service;
    private final IUsersService usersService;

    /**
     * 员工注册
     *
     * @param registerInfo 用户信息
     * @author 杜伟毅
     * @since 2025/6/8 0008 14:36
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PostMapping("/register")
    public Result<Void> employeeRegister(@RequestBody RegisterDTO registerInfo) {
        return usersService.register(registerInfo);
    }

    /**
     * 获取用户信息分页
     *
     * @author 杜伟毅
     * @since 2025/1/17 0017 23:34
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PostMapping("/page")
    public Result<Page<Users>> getUsersPage(@RequestBody UsersPageDTO dto) {
        return service.getUsersPage(dto);
    }

    /**
     * 将用户锁定
     *
     * @param id 用户id
     * @author 杜伟毅
     * @since 2025/5/11 0011 19:05
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PutMapping("/locked/{id}")
    public Result<Void> lockedUser(@PathVariable String id) {
        return service.lockedUser(id);
    }

    /**
     * 将用户解锁
     *
     * @param id 用户id
     * @author 杜伟毅
     * @since 2025/5/11 0011 19:05
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PutMapping("/unlock/{id}")
    public Result<Void> unlockUser(@PathVariable String id) {
        return service.unlockUser(id);
    }

    /**
     * 获取用户个人信息
     *
     * @param id 用户id
     * @author 杜伟毅
     * @since 2025/5/12 0012 0:00
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @GetMapping("/{id}")
    public Result<UserinfoVO> getUserinfo(@PathVariable String id) {
        return service.getUserinfo(id);
    }
}
